package com.smbms.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.smbms.dao.UserMapper;
import com.smbms.entity.User;

@Service
@Transactional
public class UserServiceImpl implements UserService{
	@Resource
	private UserMapper userMapper;
	
	@Override
	public User login(String userCode) {
		return userMapper.login(userCode);
	}
	
	@Override
	public List<User> getUserList(String userName, int userRole, int pageIndex, int pageSize) {
		//重新计算当前页码
		pageIndex = (pageIndex-1)*pageSize;
		return userMapper.getUserList(userName, userRole, pageIndex, pageSize);
	}

	@Override
	public int getUserCount(String userName, int userRole) {
		return userMapper.getUserCount(userName, userRole);
	}

	@Override
	public User getUserListById(int id) {
		return userMapper.getUserListById(id);
	}

	@Override
	public boolean deleteUser(int id) {
		boolean flag = false;
		if(userMapper.deleteUser(id)>0){
			flag = true;
		}
		return flag;
	}

	@Override
	public boolean updateUser(User user) {
		boolean flag = false;
		if(userMapper.updateUser(user)>0){
			flag = true;
		}
		return flag;
	}

	@Override
	public User getUserListByUserCode(String userCode) {
		return userMapper.getUserListByUserCode(userCode);
	}

	@Override
	public boolean addUser(User user) {
		boolean flag = false;
		if(userMapper.addUser(user)>0){
			flag = true;
		}
		return flag;
	}

	@Override
	public boolean updateUserPwd(User user) {
		boolean flag = false;
		if(userMapper.updateUserPwd(user)>0){
			flag = true;
		}
		return flag;
	}

	@Override
	public List<User> download(String userName, int userRole) {
		// TODO Auto-generated method stub
		return userMapper.download(userName, userRole);
	}

	
}
